<script setup>
import { RouterLink, RouterView, useRoute } from 'vue-router'
import { store } from './store.js'
import HeaderNav from './components/HeaderNav.vue'

const route = useRoute()
</script>

<template>
  <!-- 根据路由路径决定是否显示头部栏（登录和注册页面不显示） -->
  <Transition name="header-fade">
    <HeaderNav v-if="route.path !== '/login' && route.path !== '/register'" />
  </Transition>
  
  <div class="app-content">
    <Transition name="page-transition" mode="out-in">
      <RouterView />
    </Transition>
  </div>
  
  <!-- 全局通知弹窗 -->
  <Transition name="notification">
    <div v-if="store.notification.show" class="notification-overlay">
      <Transition name="notification-popup">
        <div class="notification-popup">
          <p>{{ store.notification.message }}</p>
          <button class="close-notification" @click="store.hideNotification()">关闭</button>
        </div>
      </Transition>
    </div>
  </Transition>
</template>

<style scoped>
header {
  line-height: 1.5;
  max-height: 100vh;
}

.logo {
  display: block;
  margin: 0 auto 2rem;
}

nav {
  width: 100%;
  font-size: 12px;
  text-align: center;
  margin-top: 2rem;
}

nav a.router-link-exact-active {
  color: var(--color-text);
}

nav a.router-link-exact-active:hover {
  background-color: transparent;
}

nav a {
  display: inline-block;
  padding: 0 1rem;
  border-left: 1px solid var(--color-border);
}

nav a:first-of-type {
  border: 0;
}

@media (min-width: 1024px) {
  header {
    display: flex;
    place-items: center;
    padding-right: calc(var(--section-gap) / 2);
  }

  .logo {
    margin: 0 2rem 0 0;
  }

  header .wrapper {
    display: flex;
    place-items: flex-start;
    flex-wrap: wrap;
  }

  nav {
    text-align: left;
    margin-left: -1rem;
    font-size: 1rem;

    padding: 1rem 0;
    margin-top: 1rem;
  }
}

/* 页面过渡动画 */
.page-transition-enter-active,
.page-transition-leave-active {
  transition: all 0.4s ease;
}

.page-transition-enter-from {
  opacity: 0;
  transform: translateX(30px);
}

.page-transition-leave-to {
  opacity: 0;
  transform: translateX(-30px);
}

/* 头部过渡动画 */
.header-fade-enter-active,
.header-fade-leave-active {
  transition: opacity 0.3s ease;
}

.header-fade-enter-from,
.header-fade-leave-to {
  opacity: 0;
}

/* 全局通知弹窗样式 */
.notification-overlay {
  position: fixed;
  top: 0;
  left: 0;
  width: 100%;
  height: 100%;
  background-color: rgba(0, 0, 0, 0.5);
  display: flex;
  justify-content: center;
  align-items: center;
  z-index: 1000;
}

.notification-popup {
  background-color: white;
  padding: 30px;
  border-radius: 8px;
  text-align: center;
  box-shadow: 0 4px 6px rgba(0, 0, 0, 0.1);
  max-width: 400px;
  width: 90%;
}

.notification-popup p {
  margin-bottom: 20px;
  color: #2c3e50;
  font-size: 16px;
}

.close-notification {
  background-color: #e74c3c;
  color: white;
  border: none;
  padding: 10px 20px;
  border-radius: 4px;
  cursor: pointer;
  font-size: 14px;
  transition: background-color 0.3s;
}

.close-notification:hover {
  background-color: #c0392b;
}

/* 通知弹窗过渡动画 */
.notification-enter-active,
.notification-leave-active {
  transition: opacity 0.3s ease;
}

.notification-enter-from,
.notification-leave-to {
  opacity: 0;
}

.notification-popup-enter-active,
.notification-popup-leave-active {
  transition: all 0.3s ease;
}

.notification-popup-enter-from {
  opacity: 0;
  transform: scale(0.8) translateY(-20px);
}

.notification-popup-leave-to {
  opacity: 0;
  transform: scale(0.8) translateY(-20px);
}
</style>
